<?php

namespace  App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * This is the model class for table "group_config".
 *
 * @property int $id
 * @property string $start_time 开始时间
 * @property string $end_time 结束时间
 * @property int $interval 间隔时间(分)
 * @property int $send_sort 发送顺序
 * @property int $images_max_count 多图最多几张
 * @property int $is_open 群发启动开关
 * @property int $user_id
 */
class GroupConfig extends Model implements IReadable
{
    /**
     * @inheritdoc
     */
    protected $table = 'group_config';
    protected $guarded = [];

    public static function getConfig($uid = null)
    {
        if (is_null($uid)) {
            $uid = \Encore\Admin\Facades\Admin::guard()->id();
        }
        return self::where("user_id", $uid)->first();
    }

    public static function createGc($uid)
    {
        $config = System::getConfig();
        $model = new self();
        $model->user_id = $uid;
        $model->setAttribute("interval", $config->robot_interval);
        $model->setAttribute("is_open", 1);
        $model->setAttribute("start_time", "08:00:00");
        $model->setAttribute("end_time", "22:00:00");
        $model->save();
        return $model;
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'start_time' => [
                'label' =>  '开始时间',
                'type' => 'time'
            ],
            'end_time' => [
                'label' => '结束时间',
                'type' => 'time'
            ],
            'interval' => [
                'label' => '间隔时间(分,请联系系统管理员设置!)',
                'type' => 'text',
            ],
          //  'send_sort' => '发送顺序',
          //  'images_max_count' => '多图最多几张',
            'is_open' => [
                'label' => '群发启动开关',
                'type' => 'radio',
                'options' => [
                    "关闭", '打开'
                ]
            ],
        ];
    }
}
